package it.heima.xmy.demo;

import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/*2. 定义测试类，编写main()方法：定义一个集合
3. 遍历这个集合，将每个Student对象中的数据按以下格式写到项目根目录下的student.txt中：
   张三,男,20,88
   李四,女,19,99*/
public class StudentTest {
    public static void main(String[] args) {
        List<Student> stuList = new ArrayList<>();
        stuList.add(new Student("张三", "男", "20", "88"));
        stuList.add(new Student("李四", "女", "19", "99"));
        FileWriter fw = null;
        try {
            fw = new FileWriter("day-09//student.txt");
            for (Student student : stuList) {
                fw.write(student.getName() + "," + student.getSex() + "," + student.getAge() + "," + student.getScore());
                fw.write("\r\n");
            }
            System.out.println("---");
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                fw.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
